<?php


function bubbleSort(&$array){
    $n = count($array);
    // 遍历所有数组元素
    for ($i = 0; $i < $n - 1; $i++) {
        // 标志位，用于检测当前这轮是否有交换
        $swapped = false;
        // 内层循环，用于比较相邻元素
        for ($j = 0; $j < $n - 1 - $i; $j++) {
            if ($array[$j]['number'] < $array[$j + 1]['number']) {
                // 交换相邻元素
                $temp = $array[$j];
                $array[$j] = $array[$j + 1];
                $array[$j + 1] = $temp;
                $swapped = true;
            }
        }

        if (!$swapped) {
            break;
        }
    }

    return $array;
}


function haversineGreatCircleDistance($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo, $earthRadius = 6371)
{
    // 将十进制度数转化为弧度
    $latFrom = deg2rad($latitudeFrom);
    $lonFrom = deg2rad($longitudeFrom);
    $latTo = deg2rad($latitudeTo);
    $lonTo = deg2rad($longitudeTo);

    $latDelta = $latTo - $latFrom;
    $lonDelta = $lonTo - $lonFrom;

    $angle = 2 * asin(sqrt(pow(sin($latDelta / 2), 2) +
            cos($latFrom) * cos($latTo) * pow(sin($lonDelta / 2), 2)));

    return $angle * $earthRadius*1000;

}







